// 最后一个单词的长度

package Leetcode;

class solution_058 {
    public int lengthOfLastWord(String s) {
        int result = 0;
        boolean start = false;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) != ' ') {
                start = true;
                result++;
            }
            if (start == true && s.charAt(i) == ' ')
                break;
        }
        return result;
    }
}

public class Solution058 {
    public int lengthOfLastWord(String s) {
        String[] split = s.trim().split("\\s+");
        return split[split.length - 1].length();
    }
}
